package com.fuxi.cloud.desreport.b;

import javax.net.ssl.*;
import java.io.*;
import java.net.URL;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;

/**
 * a
 *
 * @Author: 扫地僧
 * @CreateTime: 2021-05-03
 */
public class a {
    public a() {
    }

    private static HttpsURLConnection b(String var0, String var1) throws IOException {
        SSLContext var2 = null;

        try {
            var2 = SSLContext.getInstance("TLS");
            var2.init(new KeyManager[0], new TrustManager[]{new com.fuxi.cloud.desreport.b.a.ar()}, new SecureRandom());
        } catch (KeyManagementException var6) {
            var6.printStackTrace();
        } catch (NoSuchAlgorithmException var7) {
            var7.printStackTrace();
        }

        SSLSocketFactory var3 = var2.getSocketFactory();
        URL var4 = new URL(var0);
        HttpsURLConnection var5 = (HttpsURLConnection)var4.openConnection();
        var5.setSSLSocketFactory(var3);
        var5.setHostnameVerifier(new HostnameVerifier() {
            @Override
            public boolean verify(String arg0, SSLSession arg1) {
                return true;
            }
        });
        var5.setRequestMethod(var1);
        var5.setDoInput(true);
        var5.setDoOutput(true);
        return var5;
    }

    private static byte[] a(InputStream var0) throws IOException {
        ByteArrayOutputStream var1 = new ByteArrayOutputStream();
        byte[] var2 = new byte[1024];

        int var3;
        while((var3 = var0.read(var2)) != -1) {
            var1.write(var2, 0, var3);
        }

        byte[] var4 = var1.toByteArray();
        var1.close();
        var0.close();
        return var4;
    }

    private static void a(OutputStream var0, byte[] var1) throws IOException {
        ByteArrayInputStream var2 = new ByteArrayInputStream(var1);
        byte[] var3 = new byte[1024];

        int var4;
        while((var4 = var2.read(var3)) != -1) {
            var0.write(var3, 0, var4);
        }

        var0.flush();
        var0.close();
        var2.close();
    }

    public static byte[] a(String var0) throws IOException {
        HttpsURLConnection var1 = b(var0, "GET");
        return a(var1.getInputStream());
    }

    public static byte[] a(String var0, String var1) throws IOException {
        HttpsURLConnection var2 = b(var0, "POST");
        a(var2.getOutputStream(), var1.getBytes());
        return a(var2.getInputStream());
    }

    private static final class ar implements X509TrustManager {
        private ar() {
        }

        @Override
        public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
        }

        @Override
        public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
        }

        @Override
        public X509Certificate[] getAcceptedIssuers() {
            return null;
        }
    }
}
